
import java.util.ArrayList;
import java.util.List;
public class WeatherData implements Subject {

    private List<Observer> observers;

    private float temperature;

    public void setMessurements(float temperature) {
        this.temperature = temperature;
        notifyObservers();
    }

    public WeatherData() {
        this.observers = new ArrayList();
    }

    public void registerObserver(Observer o) {
        observers.add(o);
    }

    public void removeObserver(Observer o) {
        int i = observers.indexOf(o);
        if (i >= 0) {
            observers.remove(i);
        }
    }

    public void notifyObservers() {
        for (Observer observer : observers) {
            observer.update(temperature);
        }
    }
}